<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Cart;
use DB;

class ShopController extends Controller
{
	public $goodslist = [ 
		1=>[ 'goods_id'=>1,'goods_name'=>'谢大脚,泼辣豪放脚大','price'=>5.1 ],
		2=>[ 'goods_id'=>2,'goods_name'=>'尼古拉斯.赵四,亚洲舞王','price'=>2.1 ],
		3=>[ 'goods_id'=>3,'goods_name'=>'爱新觉罗,刘能,磕巴','price'=>3.1 ],
		4=>[ 'goods_id'=>4,'goods_name'=>'西门.谢广坤,秃顶','price'=>4.1 ],
	];
	public function index(){
		//$charu =  DB::table('tbmember')->insert(['openID'=>'123456']);
		//$charu = DB::table('tbmember')->where('openID','=','123456')->update(['name'=>'用户']);

		

		return view('index' , ['gs'=>$this->goodslist]);
	}
	public function goods($id){
		$goods = $this->goodslist[$id];
		return view('goods' , ['goods'=>$goods]);
	}
	public function buy($id){

		$goods = $this->goodslist[$id];
		// print_r($goods);exit;
		Cart::add($goods['goods_id'] , $goods['goods_name'] , $goods['price'] ,1 ,array());
		return redirect('/cart');
	}
	public function cart(){
		$goods = Cart::getContent();
		$total = Cart::getTotal();
		return view('cart',['goods'=>$goods , 'to'=>$total]);
		// var_dump($goods);  
	}
	public function cle(){
		Cart::clear();
		return redirect('/');
	}
}
